package com.simpleplayer.services;

import androidx.annotation.NonNull;

import java.util.ArrayList;

public class HTMLResourceExtractor {

    private static final String TAG = "HTMLResourceExtractor";

    public static interface Listener {
        void onExtractFinish(HTMLResourceExtractor extractor, WebContents webContents);
    }

    // 视频信息
    public static class VideoInfo {
        public ArrayList<String> sources;  // 视频源，可能有多个
        public String poster;  // 封面uri
        public String title;   // 视频标题
    }

    // 音频信息
    public static class AudioInfo {
        public ArrayList<String> sources;  // 音频源，可能有多个
    }

    // 图片信息
    public static class ImageInfo {
        public String uri;  // 图片源地址
        public String name; // 图片名称
    }

    // 超链接信息
    public static class LinkInfo {
        public String href; // 目标地址
        public String type; // 链接目标的 MIME 类型
    }

    // 提取结果
    public static class WebContents {
        private String mUri;
        private String mContent; // 网址内容
        private ArrayList<VideoInfo> mVideos;
        private ArrayList<AudioInfo> mAudios;
        private ArrayList<ImageInfo> mImages;
        private ArrayList<LinkInfo> mLinks;

        public String getUri() { return mUri; }

        public String getContent() { return mContent; }

        public ArrayList<VideoInfo> getVideos() { return mVideos; }

        public ArrayList<AudioInfo> getAudios() { return mAudios; }

        public ArrayList<ImageInfo> getImages() { return mImages; }

        public ArrayList<LinkInfo> getLinks() { return mLinks; }

        public WebContents appendUri(String uri) {
            mUri = uri;
            return this;
        }

        public WebContents appendContent(String content) {
            mContent = content;
            return this;
        }

        public WebContents appendVideoInfos(ArrayList<VideoInfo> videos) {
            mVideos = videos;
            return this;
        }

        public WebContents appendAudioInfos(ArrayList<AudioInfo> audios) {
            mAudios = audios;
            return this;
        }

        public WebContents appendImageInfos(ArrayList<ImageInfo> images) {
            mImages = images;
            return this;
        }

        public WebContents appendLinkInfos(ArrayList<LinkInfo> links) {
            mLinks = links;
            return this;
        }
    }

    public void extract(@NonNull String url, Listener listener) {}

    public static HTMLResourceExtractor getDefault() {
        return new JsoupHTMLResourceExtractor();
    }
}
